package com.bwie.bwedu.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bwie.bwedu.R;
import com.bwie.bwedu.bean.Student;
import com.bwie.bwedu.utils.PhoneUtil;

import java.util.List;

/**
 * Created by Administrator on 2016/7/22.
 */
public class Trackadapter extends MyBaseAdapter<Student> {


    public Trackadapter(Context context, List<Student> list) {
        super(context, list);
    }

    @Override
    public View myView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView=View.inflate(getContext(),R.layout.fragment_track_item,null);
            holder=new ViewHolder();
            holder.name= (TextView) convertView.findViewById(R.id.track_item_name);
            holder.phone= (TextView) convertView.findViewById(R.id.track_item_phone);
            holder.z_name= (TextView) convertView.findViewById(R.id.track_item_z_name);
            holder.z_phone= (TextView) convertView.findViewById(R.id.track_item_z_phone);
            holder.address= (TextView) convertView.findViewById(R.id.track_item_address);
            holder.id_card= (TextView) convertView.findViewById(R.id.track_item_ID_card);
            holder.date= (TextView) convertView.findViewById(R.id.track_item_date);
            holder.layout=(LinearLayout) convertView.findViewById(R.id.login_layout);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }

        listener(holder,position);
        holder.name.setText(getList().get(position).gxxm);
        holder.phone.setText(getList().get(position).gxdh);
        holder.z_name.setText(getList().get(position).xm);
        holder.z_phone.setText(getList().get(position).grsj);
        holder.address.setText(getList().get(position).jg);
        holder.id_card.setText(getList().get(position).sfzh);
        holder.date.setText(getList().get(position).createDate);
        return convertView;
    }

    private void listener(final ViewHolder holder, final int position) {
        holder.phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PhoneUtil.phone(getList().get(position).gxdh,(Activity)getContext(),holder.layout);
            }
        });
        holder.z_phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PhoneUtil.phone(getList().get(position).grsj,(Activity)getContext(),holder.layout);
            }
        });

    }

    class ViewHolder{
        TextView name;
        TextView phone;
        TextView z_name;
        TextView z_phone;
        TextView address;
        TextView id_card;
        TextView date;
        LinearLayout layout;
    }
}
